package api

import (
	"fmt"
	"github.com/gin-gonic/gin"
	"github.com/gorilla/websocket"
	"sync"
)

type Message struct {
	UserId string `json:"userId"`
	SendId string `json:"sendId"`
}
type Node struct {
	Client *websocket.Conn
	Data   chan []byte
}

var ClientMap = make(map[string]*Node)

var wsg sync.WaitGroup

func Chat(c *gin.Context) {
	var chat Message
	c.ShouldBind(&chat)
	sendid := chat.SendId
	userid := chat.UserId
	msg := &Message{
		UserId: userid,
		SendId: sendid,
	}

	upgr := websocket.Upgrader{
		ReadBufferSize:  1024,
		WriteBufferSize: 1024,
	}
	fmt.Println(msg)
	upgr.Upgrade(c.Writer, c.Request, nil)
	wsg.Add(4)

}
